package com.ymatou.iapi.godmch.testcase;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.addProviderBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.iapi.godmch.parameter.getProviderByIdBean;
import com.ymatou.iapi.godmch.service.addProviderCall;
import com.ymatou.iapi.godmch.service.getProviderByIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.serviceRelation;
import com.ymttest.database.sqlwapper.godmch.serviceProviderWapper;
import com.ymttest.database.sqlwapper.godmch.serviceRelationWapper;
import com.ymttest.utils.TestDataManager;
/**
*服务商详情byid
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getProviderById{
	private static getProviderByIdBean bean;
	private static getProviderByIdCall call;
	addProviderBean addbean=new addProviderBean();
	addProviderCall addcall=new   addProviderCall();
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ; 
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("服务商详情byid");
	}

	@Before
	public void caseUp() {
		bean=new getProviderByIdBean();
		call=new getProviderByIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProviderById_001() {
		Logger.start(true,"正例-服务商详情byid-渠道商有服务商");
		try {
			
			createmchBean createmchBean=GodmchManageCallService.InitAddProvider();
			int providerId1=createmchBean.getMchId();
			
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//修改服务商名称
			editmchBean editBean=GodmchManageCallService.IniteditmachBean(providerId1);
			editBean.setMchTitle("测试渠道商的所有服务商_"+TestDataManager.getRandomIntNum(10));
			GodmchManageCallService.editmachCall(editBean);
			
			GodmchManageCallService.InitAddServiceRelation(providerId1,mchBean.getMchId(),1);		
			
			bean.setProviderId(providerId1);
			call.setData(bean);
			call.callService();		
			
			//验证
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			//Provider 获取providerid
			HashMap hMap=new HashMap();
			hMap.put("providerId", bean.getProviderId());
			//mchTitle
			serviceProviderWapper sWapper=new serviceProviderWapper();
			Map pMap=sWapper.selectProviders(hMap).get(0);
			
			Logger.verifyEquals(Integer.parseInt(pMap.get("providerId").toString()), call.getProviderId(), "验证ProviderId");
			Logger.verifyEquals(pMap.get("mchTitle"), call.getName(), "验证Name");
			Logger.verifyEquals(editBean.getMchTitle(), call.getName(), "验证Name");
			Logger.verifyEquals(Integer.parseInt(pMap.get("state").toString())==0?true:false, call.getEnabled(), "验证Enabled");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProviderById_002() {
		Logger.start(true,"正例-服务商详情byid-渠道商没有服务商");
		try {
			
			createmchBean createmchBean=GodmchManageCallService.InitAddProvider();
			int providerId1=createmchBean.getMchId();
			
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//修改服务商名称
			editmchBean editBean=GodmchManageCallService.IniteditmachBean(providerId1);
			editBean.setMchTitle("测试渠道商的所有服务商_"+TestDataManager.getRandomIntNum(10));
			GodmchManageCallService.editmachCall(editBean);
			//GodmchManageCallService.InitAddServiceRelation(providerId1,mchBean.getMchId(),1);		
			bean.setProviderId(providerId1);
			call.setData(bean);
			call.callService();		
			
			//验证
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			//Provider 获取providerid
			HashMap hMap=new HashMap();
			hMap.put("providerId", bean.getProviderId());
			//mchTitle
			serviceProviderWapper sWapper=new serviceProviderWapper();
			Map pMap=sWapper.selectProviders(hMap).get(0);
			
			Logger.verifyEquals(Integer.parseInt(pMap.get("providerId").toString()), call.getProviderId(), "验证ProviderId");
			Logger.verifyEquals(pMap.get("mchTitle"), call.getName(), "验证Name");
			Logger.verifyEquals(editBean.getMchTitle(), call.getName(), "验证Name");
			Logger.verifyEquals(Integer.parseInt(pMap.get("state").toString())==0?true:false, call.getEnabled(), "验证Enabled");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProviderById_003() {
		Logger.start(true,"正例-服务商详情byid-id为空");
		try {
			
			bean.setProviderId(null);
			call.setData(bean);
			call.callService();			
			
			//验证
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}